﻿@model ProductAttributeMappingModel

@using Nop.Core.Domain.Catalog
@using Nop.Services

<script>
    $(document).ready(function() {
        $("#@Html.IdFor(model => model.AttributeControlTypeId)").change(toggleAttributeControlType);

        toggleAttributeControlType();
    });

    function toggleAttributeControlType() {
        var selectedAttributeControlTypeId = $("#@Html.IdFor(model => model.AttributeControlTypeId)").val();
        //validation
        if (selectedAttributeControlTypeId == @(((int) AttributeControlType.TextBox).ToString())) {
            $('#pnlValidationMinLength').show();
            $('#pnlValidationMaxLength').show();
            $('#pnlValidationFileMaximumSize').hide();
            $('#pnlValidationFileAllowedExtensions').hide();
            $('#pnlDefaultValueLocalized').show();
            $('#pnlDefaultValue').show();
        } else if (selectedAttributeControlTypeId == @(((int) AttributeControlType.MultilineTextbox).ToString())) {
            $('#pnlValidationMinLength').show();
            $('#pnlValidationMaxLength').show();
            $('#pnlValidationFileMaximumSize').hide();
            $('#pnlValidationFileAllowedExtensions').hide();
            $('#pnlDefaultValueLocalized').show();
            $('#pnlDefaultValue').show();
        } else if (selectedAttributeControlTypeId == @(((int) AttributeControlType.FileUpload).ToString())) {
            $('#pnlValidationMinLength').hide();
            $('#pnlValidationMaxLength').hide();
            $('#pnlValidationFileMaximumSize').show();
            $('#pnlValidationFileAllowedExtensions').show();
            $('#pnlDefaultValueLocalized').hide();
            $('#pnlDefaultValue').hide();
            $("#@Html.IdFor(model => model.DefaultValue)").val('');
            @for (var item = 0; item < Model.Locales.Count; item++)
            {
                <text>$("#@Html.IdFor(model => model.Locales[item].DefaultValue)").val('');</text>
            }
        } else {
            $('#pnlValidationMinLength').hide();
            $('#pnlValidationMaxLength').hide();
            $('#pnlValidationFileMaximumSize').hide();
            $('#pnlValidationFileAllowedExtensions').hide();
            $('#pnlDefaultValueLocalized').hide();
            $('#pnlDefaultValue').hide();
            $("#@Html.IdFor(model => model.DefaultValue)").val('');
            @for (var item = 0; item < Model.Locales.Count; item++)
            {
                <text>$("#@Html.IdFor(model => model.Locales[item].DefaultValue)").val('');</text>
            }
        }

        //values
        if (selectedAttributeControlTypeId == @(((int) AttributeControlType.DropdownList).ToString()) ||
            selectedAttributeControlTypeId == @(((int) AttributeControlType.RadioList).ToString()) ||
            selectedAttributeControlTypeId == @(((int) AttributeControlType.Checkboxes).ToString()) ||
            selectedAttributeControlTypeId == @(((int) AttributeControlType.ColorSquares).ToString()) ||
            selectedAttributeControlTypeId == @(((int) AttributeControlType.ImageSquares).ToString()) ||
            selectedAttributeControlTypeId == @(((int) AttributeControlType.ReadonlyCheckboxes).ToString())) {
            $('[data-panel-name=product-attribute-mapping-values]').show();
        } else {
            $('[data-panel-name=product-attribute-mapping-values]').hide();
        }
    }
</script>
<input asp-for="ProductId" type="hidden" />

<div class="panel-body">
    <div class="form-group">
        <div class="col-md-3">
            <nop-label asp-for="ProductAttributeId" />
        </div>
        <div class="col-md-9">
            <nop-select asp-for="ProductAttributeId" asp-items="Model.AvailableProductAttributes" />
            <span asp-validation-for="ProductAttributeId"></span>
        </div>
    </div>
    @(Html.LocalizedEditor<ProductAttributeMappingModel, ProductAttributeMappingLocalizedModel>("productattribute-localized",
    @<div>
        <div class="form-group">
            <div class="col-md-3">
                <nop-label asp-for="@Model.Locales[item].TextPrompt" />
            </div>
            <div class="col-md-9">
                <nop-editor asp-for="@Model.Locales[item].TextPrompt" />
                <span asp-validation-for="@Model.Locales[item].TextPrompt"></span>
            </div>
        </div>
        <input type="hidden" asp-for="@Model.Locales[item].LanguageId" />
    </div>
,
    @<div>
        <div class="form-group">
            <div class="col-md-3">
                <nop-label asp-for="TextPrompt" />
            </div>
            <div class="col-md-9">
                <nop-editor asp-for="TextPrompt" />
                <span asp-validation-for="TextPrompt"></span>
            </div>
        </div>
    </div>
))
    <div class="form-group">
        <div class="col-md-3">
            <nop-label asp-for="IsRequired" />
        </div>
        <div class="col-md-9">
            <nop-editor asp-for="IsRequired" />
            <span asp-validation-for="IsRequired"></span>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-3">
            <nop-label asp-for="AttributeControlTypeId" />
        </div>
        <div class="col-md-9">
            <nop-select asp-for="AttributeControlTypeId" asp-items="@(((AttributeControlType)Model.AttributeControlTypeId).ToSelectList())" />
            <span asp-validation-for="AttributeControlTypeId"></span>
        </div>
    </div>
    @(Html.LocalizedEditor<ProductAttributeMappingModel, ProductAttributeMappingLocalizedModel>("pnlDefaultValueLocalized",
    @<div>
        <div class="form-group advanced-setting">
            <div class="col-md-3">
                <nop-label asp-for="@Model.Locales[item].DefaultValue"/>
            </div>
            <div class="col-md-9">
                <nop-editor asp-for="@Model.Locales[item].DefaultValue"/>
                <span asp-validation-for="@Model.Locales[item].DefaultValue"></span>
            </div>
        </div>
        <input type="hidden" asp-for="@Model.Locales[item].LanguageId" /> 
    </div>
,
    @<div>
        <div class="form-group advanced-setting" id="pnlDefaultValue">
            <div class="col-md-3">
                <nop-label asp-for="DefaultValue"/>
            </div>
            <div class="col-md-9">
                <nop-editor asp-for="DefaultValue"/>
                <span asp-validation-for="DefaultValue"></span>
            </div>
        </div>
     </div>
))
    <div class="form-group">
        <div class="col-md-3">
            <nop-label asp-for="DisplayOrder" />
        </div>
        <div class="col-md-9">
            <nop-editor asp-for="DisplayOrder" />
            <span asp-validation-for="DisplayOrder"></span>
        </div>
    </div>
    <div class="form-group" id="pnlValidationMinLength">
        <div class="col-md-3">
            <nop-label asp-for="ValidationMinLength" />
        </div>
        <div class="col-md-9">
            <nop-editor asp-for="ValidationMinLength" />
            <span asp-validation-for="ValidationMinLength"></span>
        </div>
    </div>
    <div class="form-group" id="pnlValidationMaxLength">
        <div class="col-md-3">
            <nop-label asp-for="ValidationMaxLength" />
        </div>
        <div class="col-md-9">
            <nop-editor asp-for="ValidationMaxLength" />
            <span asp-validation-for="ValidationMaxLength"></span>
        </div>
    </div>
    <div class="form-group" id="pnlValidationFileAllowedExtensions">
        <div class="col-md-3">
            <nop-label asp-for="ValidationFileAllowedExtensions" />
        </div>
        <div class="col-md-9">
            <nop-editor asp-for="ValidationFileAllowedExtensions" />
            <span asp-validation-for="ValidationFileAllowedExtensions"></span>
        </div>
    </div>
    <div class="form-group" id="pnlValidationFileMaximumSize">
        <div class="col-md-3">
            <nop-label asp-for="ValidationFileMaximumSize" />
        </div>
        <div class="col-md-9">
            <nop-editor asp-for="ValidationFileMaximumSize" />
            <span asp-validation-for="ValidationFileMaximumSize"></span>
        </div>
    </div>
</div>